package route

import (
	"svvenus/conf"
	"svvenus/vgame/logic"
	"svvenus/vpub"
	"svvenus/vpub/constants"
	"svvenus/vpub/worker"
	"svvenus/zlog"
	"time"
)

// CmdRegister
// @Description: 指令注册
func CmdRegister() {

	worker.CmdlineWorkerBinds([]string{"save", "服务器存档"}, save)
	worker.CmdlineWorkerBinds([]string{"exit", "服务器关闭"}, exit)
	worker.CmdlineWorkerBinds([]string{"conf", "config"}, config)
	worker.CmdlineWorkerBinds([]string{"lock", "服务器锁定"}, lock)
	worker.CmdlineWorkerBinds([]string{"unlock", "服务器解锁"}, unlock)

	worker.CmdlineWorkerBind("players", players)

	worker.CmdlineWorkerBind("test", test)
}

// save
// @Description: 服务器存档
func save() {

	logic.ServerSave()

	zlog.Info("服务器存档 end .............")
}

// exit
// @Description: 服务器退出
func exit() {

	logic.ServerSave()

	zlog.Info("服务器存档 完毕 5秒后关闭服务器 .............")

	time.Sleep(time.Second * 5)

	vpub.Cancel()
}

func config() {
	conf.InitMapAll()
	conf.InitExtGame()
}

// lock
// @Description: 服务器锁定
func lock() {
	constants.ServerLocked = true
	zlog.Info("服务器 限制登录")
}

// unlock
// @Description: 服务器解锁
func unlock() {
	constants.ServerLocked = false
	zlog.Info("服务器 不限制登录")
}

func players() {
	logic.MapPlayer.Range(func(key, value interface{}) bool {
		p := value.(*logic.Player)
		zlog.Debug(p.IdString(), p.Name)
		return true
	})
}

// test
// @Description: 测试
func test() {
	zlog.Info("func Test start .............")

	defer constants.GetPanic()

	//var countryCapitalMap = make(map[int]int)
	var countryCapitalMap map[int]int
	countryCapitalMap[1] += 1

	zlog.Trace("func Test end .............")
	zlog.Debug("func Test end .............")
	zlog.Print("func Test end .............")
	zlog.Info("func Test end .............")
	zlog.Warn("func Test end .............")
	zlog.Error("func Test end .............")
}
